<?php

namespace App\Dao;

use App\Model\Anchor;
use App\Model\Online;
use App\Model\Order;
use App\Utils\MemcacheClient;
use Hyperf\Context\ApplicationContext;

class OrderDao
{
    private static $instance;

    public static function getInstance()
    {
        if (!self::$instance) {
            self::$instance = Applicationcontext::getcontainer()->get(self::class);
        }
        return self::$instance;
    }

    /**
     * 检测是否弹出首充弹框
     * @param $uid
     * @return int
     */
    public function checkFirstRecharge($uid)
    {
        // $sql = "select * from {$this->table} where `uid` = '$uid' and consume_type<50 and consume_type>6 and pay_status=1 and notify_status=1";
        // $pd = $this->createCommand($sql);
        // $pd->execute();
        // $res = $pd->fetch(PDO::FETCH_ASSOC);
        $exists = Order::query()->where([
            ['uid', '=', $uid],
            ['consume_type', '<', 50],
            ['consume_type', '>', 2],
            ['pay_status', '=', 1],
            ['notify_status', '=', 1],
        ])->exists();
        return $exists ? 0 : 1;// empty($res) ? 1 : 0;
    }

    public function findOrderByOrderId($order_id)
    {
        $order_id = trim($order_id);
        // if (empty($order_id)) return false;
        // $sql = "select * from {$this->table} where `order_id` = '$order_id'";
        // $pd = $this->createCommand($sql);
        // $pd->execute();
        // return $pd->fetch(PDO::FETCH_ASSOC);
        $data = Order::query()->where('order_id', $order_id)->first();
        return modelToArray($data);
    }


}